import react from "@vitejs/plugin-react";
import { ConfigEnv, UserConfig, defineConfig, loadEnv } from "vite";
import UnoCSS from "unocss/vite";
// 引入node模块path
import path from "path";
// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
  const env: Record<string, string> = loadEnv(mode, process.cwd());
  return {
    plugins: [UnoCSS(), react()],
    // 配置@和~路径
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
        "~": path.resolve(__dirname, "./"),
      },
    },
    // 配置代理
    server: {
      port: Number(env.VITE_APP_PORT),
      host: true,
      open: false,
      proxy: {
        [env.VITE_APP_BASE_API]: {
          target: "https://3mrod2658820.vicp.fun",
          changeOrigin: true,
          secure: false,
          rewrite: (path) =>
            path.replace(new RegExp("^" + env.VITE_APP_BASE_API), ""),
        }, // base api
      }, // proxy
    }, //server
  };
});
